package edu.zut.cn.utils;


import edu.zut.cn.domain.entity.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 *  SecurityUtils工具类
 *
 * @author 张小訫
 */
public class SecurityUtils {

    /**
     * 获取Authentication
     */
    public static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    /**
     * 获取用户
     **/
    public static LoginUser getLoginUser() {
        return (LoginUser) getAuthentication().getPrincipal();
    }

    /**
     * 获取用户Id
     */
    public static Long getUserId() {
        return getLoginUser().getUser().getId();
    }

}